<?php
		  
	include ("Outils.inc");
	require ("connect.php");	
		  
	if ( !isset($_COOKIE['identite']) ) {
		  $Nom = ($_POST['Nom']);
		  $Code = ($_POST['Code']);
		  $mois = 60 * 60 * 24 * 30;

		 identification($Nom, $Code, $serv, "IdentificationC.php");
		 //la fonction identification quitte si l'identification a �chou�
		 
		  	setcookie('identite[0]', "$Nom", time()+ $mois);
			setcookie('identite[1]', "$Code", time()+ $mois);
			$cookieEnvoye = true;
	}
	else {
		$cookieEnvoye = true;
		$identite = $_COOKIE['identite'];
		$Nom = $identite[0];
		$Code = $identite[1];

	}
		  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css" media="screen">@import "style.css";</style>

<title> VideoExpress - PHP Projet</title></head>

<body>
<div class="center">
<div class="outer" id="outer">
<div class="outer_l">
<div class="outer_r">

<!--ENTETE & MENU-->
<?php 

banniere("VideoExpress","Nguyen Tat Son Tung");
?>
<!--FIN ENTETE & MENU-->


<!--CONTENT-->
<div class="wrap main_content_max" id="main_content">
<div class="content">
<table class="blog" cellpadding="0" cellspacing="0">
<tr><td valign="top"><div>
		
<table class="contentpaneopen"><tr>
<td class="contentheading" width="100%">COMMANDE DE CASSETTES</td></tr></table>
<table class="contentpaneopen"><tr><td valign="top" colspan="2">
<?php
require ("connect.php");

/*$Code=$_POST["Code"];
$Nom=$_POST["Nom"];*/
$count=0;
$expire=0;
echo "<table><tr><td><img src='images/pages.png'><br \></td>
	<td><div align='right'>
	<form method='POST' action='Deconnecte.php' \">
Deconnect� <input type='image' src='images/deconnect.ico' alt='Deconnecte'>
</form></td></tr></table><br \>"; 


for ($i=1;$i<3;$i++){
if ( isset($_POST["Num$i"]) && ($_POST["Num$i"])!=""){

$NoFilm=$_POST["NoFilm$i"];
$NoExemplaire=$_POST["Exi$i"];
$checked=$_POST["Num$i"];


if ($checked == 'off'){

$r1 = "UPDATE `cassettes` SET `Statut` = 'disponible' WHERE `NoFilm` LIKE '$NoFilm' AND `NoExemplaire` = '$NoExemplaire'";
DB_execSQL($r1,$serv);					
DB_execSQL("DELETE FROM `empres` WHERE `NoFilm` = '$NoFilm' AND `NoExemplaire` = '$NoExemplaire';", $serv);

}else{

$req="SELECT * 
FROM empres e, cassettes c
WHERE e.NoFilm = c.NoFilm
AND e.NoExemplaire = c.NoExemplaire
AND e.CodeAbonne = '$Code'
AND c.Statut = 'reservee'
AND e.NoFilm = '$NoFilm'
AND e.NoExemplaire = '$NoExemplaire'
AND (TIMEDIFF(NOW(), e.DateEmpRes) > '00:00:10')";

$resul = DB_execSQL($req,$serv);
$count = mysql_num_rows($resul);


if ( $count != 0 ){

$r1 = "UPDATE `cassettes` SET `Statut` = 'disponible' WHERE `NoFilm` LIKE '$NoFilm' AND `NoExemplaire` = '$NoExemplaire'";

DB_execSQL($r1,$serv);
					
DB_execSQL("DELETE FROM `empres` WHERE `NoFilm` LIKE '$NoFilm' AND `NoExemplaire` LIKE '$NoExemplaire';", $serv);
$expire++;

} else {

$r2="UPDATE `abonnes` `a`"
	."SET `a`.`NbCassettes` = `a`.`NbCassettes` + '1'"
	."WHERE `a`.`Code` LIKE '$Code'"
	."AND `a`.`Nom` LIKE '$Nom'";

$r3="UPDATE `cassettes` `c`"
	."SET `c`.`Statut` = 'empruntee'"
	."WHERE `c`.`NoFilm` LIKE '$NoFilm'"
	."AND `c`.`NoExemplaire` LIKE '$NoExemplaire'";

DB_execSQL($r2,$serv);
DB_execSQL($r3,$serv);
			
echo "<p><h2>Film num&eacute;ro $NoFilm command�</p><br \>";
$count++;

}
			
}
		
}
}

if (($expire != 0)){
echo " <h2>La r�servation n'est que valid� pendant 10 secondes . Vous avez d�pass� le temps limit� . Veuillez-vous refaire .<br \><br \>
<form method='POST' action='Commande.php'>
Cliquez ici pour essayer de nouveau  <input type='submit' value='Cliquez-moi' STYLE='font-family:Garamond; font-size:medium;
font-style:normal; background:#444444 none; color:#FFF; border: 1px dotted'>
</form>";
} else {						
if ($count == 0) {
echo  "<h2>Vous avez command� aucun film disponible<h2>";
}else
{ 
echo "<h2>Votre commande a �t� bien enregistr� . Merci de votre visite !";
}
}

 
?>
</td></tr></table>

<span class="article_separator">&nbsp;</span>

</div></td></tr></table>
</div>
</div>
</div>
</div>
</div>
</div>
<!--FIN CONTENT-->

<!-- PIED -->
<?php include ("inc/inc-pied.php"); ?>
<!-- FIN - PIED --> 
</body>
</html>